detect_machine
detect_machine
A detection method that combines AMD (Answering Machine Detection) and fax detection.
Detect whether the user on the other end of the call is a machine (fax, voicemail, etc.) or a human.
The detection event(s) will be sent to the specified status_url as a POST request, and the current detection state
or final result will also be saved in the detect_result variable.
Properties
detect_machine
An object that accepts the following properties.
detect_machine.detect_message_end
Whether to keep detecting after the call is classified as a machine. If false, detection can finish as soon as a machine is detected. If true, detection continues until a beep or the end of the voicemail greeting is detected, or until timeout. A detected beep ends detection either way.
detect_machine.detectors
Comma-separated string of detectors to enable. Valid Values: amd, fax
detect_machine.end_silence_timeout
How long to wait for voice activity to finish (in seconds). Must be at least 1; smaller values, such as 0 or 0.5, are rejected.
detect_machine.initial_timeout
How long to wait for initial voice activity before giving up (in seconds). Must be at least 1; smaller values, such as 0 or 0.5, are rejected.
detect_machine.machine_ready_timeout
How long to wait for voice activity to finish before firing the READY event (in seconds). Must be at least 1; smaller values, such as 0 or 0.5, are rejected.
detect_machine.machine_voice_threshold
The number of seconds of ongoing voice activity required to classify as MACHINE. Must be at least 1; smaller values, such as 0 or 0.5, are rejected.
detect_machine.machine_words_threshold
The minimum number of words that must be detected in a single utterance before classifying the call as MACHINE. Must be at least 1; 0 is rejected.
detect_machine.status_url
The HTTP(S) URL to deliver detector events to. Learn more about status callbacks.
detect_machine.timeout
The maximum time to run the detector (in seconds).
detect_machine.tone
The tone to detect. Only the remote side tone will be received. (CED or CNG) Used for fax detection.
detect_machine.wait
If false, the detector will run asynchronously and status_url must be set. If true, the detector will wait for detection to complete before moving to the next SWML instruction.
Variables
The following variables are set when the detect_machine method returns.
You can reference these variables in your SWML script utilizing the ${variable} syntax.
With wait: true (the default), they hold the final detection result. With wait: false, the method returns as soon as detection starts: detect_result is detecting, detect_machine_beep is false, and detect_ms is "-1". Later detection events go to status_url and do not update these variables.
detect_result
The lowercase SWML variable value for the current detection state or final result. failed means the detection request failed or returned no result.
Callback lifecycle events such as READY, NOT_READY, and finished are never assigned to this variable.
detect_machine_beep
Whether a beep was detected. true if detected. Only reflects a completed measurement with wait: true. When detect_result is failed, this variable is not updated.
detect_ms
The number of milliseconds the detection took, stored as a string containing an integer (for example "3200"). "-1" when no duration is available, including with wait: false. When detect_result is failed, this variable is not updated.
StatusCallbacks
Status callbacks are asynchronous, best-effort HTTP notifications: delivery can be delayed or fail silently — if your server is unreachable, the callback simply never arrives. Don’t gate time-critical or business-critical actions solely on receiving one. Confirm state via the REST API before acting, or use a transport with visible failure modes — see Status callback reliability.
A POST request will be sent to status_url with a JSON payload like the following for each detection event:
event_type
The type of event: calling.call.detect for detection events.
event_channel
The channel for the event, includes the SWML session ID.
timestamp
Unix timestamp (float) when the event was generated.
project_id
The project ID associated with the call.
space_id
The Space ID associated with the call.
params
An object containing detection-specific parameters.
params.control_id
The control ID for this detect operation.
params.detect
Detection result details (see subfields below).
params.detect.type
The type of detection. Valid values: machine or fax.
params.detect.params
The detector event details.
params.detect.params.event
The detector event value in the status callback payload. The values depend on params.detect.type:
machine: detection outcome values areHUMAN,MACHINE, andUNKNOWN; lifecycle marker values areREADY,NOT_READY, andfinished.fax: the detected fax tone,CNGorCED; the lifecycle markerfinishedmarks the end of fax detection.
READY, NOT_READY, finished, CNG, and CED only appear in callback payloads and are not valid ${detect_result} values.
The lowercase finished value is intentional.
params.detect.params.beep
Present and set to true when a beep was detected. Absent when no beep has been detected.
params.call_id
The call ID.
params.node_id
The node handling the call.
params.segment_id
The segment ID for this part of the call.
If the detection request fails, status_url can instead receive an event with event_type set to calling.error. Its params holds an error object that describes the failure and a request object with the request that failed, in place of params.detect.